package o;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.hwid.core.constants.HwAccountConstants;

public final class fg {
    public static boolean ˋ(@NonNull Activity activity, @NonNull Intent intent) {
        if (VERSION.SDK_INT >= 16) {
            return activity.shouldUpRecreateTask(intent);
        }
        String action = activity.getIntent().getAction();
        return (action == null || action.equals("android.intent.action.MAIN")) ? false : true;
    }

    public static void ॱ(@NonNull Activity activity, @NonNull Intent intent) {
        if (VERSION.SDK_INT >= 16) {
            activity.navigateUpTo(intent);
            return;
        }
        intent.addFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
        activity.startActivity(intent);
        activity.finish();
    }

    @Nullable
    public static Intent ˋ(@NonNull Activity activity) {
        if (VERSION.SDK_INT >= 16) {
            Intent parentActivityIntent = activity.getParentActivityIntent();
            if (parentActivityIntent != null) {
                return parentActivityIntent;
            }
        }
        String ˏ = ˏ(activity);
        if (ˏ == null) {
            return null;
        }
        ComponentName componentName = new ComponentName(activity, ˏ);
        try {
            if (ˊ(activity, componentName) == null) {
                return Intent.makeMainActivity(componentName);
            }
            return new Intent().setComponent(componentName);
        } catch (NameNotFoundException e) {
            Log.e("NavUtils", "getParentActivityIntent: bad parentActivityName '" + ˏ + "' in manifest");
            return null;
        }
    }

    @Nullable
    public static Intent ˋ(@NonNull Context context, @NonNull ComponentName componentName) throws NameNotFoundException {
        String ˊ = ˊ(context, componentName);
        if (ˊ == null) {
            return null;
        }
        ComponentName componentName2 = new ComponentName(componentName.getPackageName(), ˊ);
        if (ˊ(context, componentName2) == null) {
            return Intent.makeMainActivity(componentName2);
        }
        return new Intent().setComponent(componentName2);
    }

    @Nullable
    public static String ˏ(@NonNull Activity activity) {
        try {
            return ˊ(activity, activity.getComponentName());
        } catch (Throwable e) {
            throw new IllegalArgumentException(e);
        }
    }

    @Nullable
    public static String ˊ(@NonNull Context context, @NonNull ComponentName componentName) throws NameNotFoundException {
        ActivityInfo activityInfo;
        String str;
        PackageManager packageManager = context.getPackageManager();
        if (VERSION.SDK_INT >= 24) {
            activityInfo = packageManager.getActivityInfo(componentName, 640);
        } else {
            activityInfo = packageManager.getActivityInfo(componentName, 640);
        }
        if (VERSION.SDK_INT >= 16) {
            str = activityInfo.parentActivityName;
            if (str != null) {
                return str;
            }
        }
        if (activityInfo.metaData == null) {
            return null;
        }
        str = activityInfo.metaData.getString("android.support.PARENT_ACTIVITY");
        if (str == null) {
            return null;
        }
        if (str.charAt(0) == '.') {
            return context.getPackageName() + str;
        }
        return str;
    }
}
